<?php

/**
 * alltosun.com 获取表情 emotion.php
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 郭莹雪 (guoyx@alltosun.com) $
 * $Date: 2012-3-7 下午01:01:18 $
*/

class emotion_widget
{
    public function emotion_sinaweibo()
    {
        $site_name = 'sinaweibo';

        $_SESSION[$site_name]['last_key']['oauth_token'] = '51aff37752d6fce92c701b445aceebf7';
        $_SESSION[$site_name]['last_key']['oauth_token_secret'] = '32b3b51e8523beecc940cfa0276f2591';

        $list = AnOpenApi($site_name)->getEmotions();
        $site_id = get_site_id($site_name);
        $emotion_category = _model('emotion_category')->getList(array('site_id'=>$site_id));

        foreach ($list as $v) {
            $v['site_id'] = $site_id;
            $v['value'] = $v['phrase'];
            $v['phrase'] = trim($v['phrase'], ']');
            $v['phrase'] = trim($v['phrase'], '[');
            $v['icon'] = $v['url'];
            if (!$v['category']) {
                $v['category'] = '默认';
            }
            if (!_uri('emotion_category', array('title'=>$v['category'], 'site_id'=>get_site_id('sinaweibo')))) {
                _model('emotion_category')->create(array('title'=>$v['category'], 'site_id'=>get_site_id('sinaweibo')));
            }
            if (!_uri('emotion', array('phrase'=>$v['phrase'], 'site_id'=>get_site_id('sinaweibo'), 'category'=>$v['category']))) {
                _model('emotion')->create($v);
            }
        }
        mail('liw@alltosun.com', 'sinaweibo_emotion', var_export($list, TRUE));
        echo "ok";
    }

    public function emotion_qqweibo()
    {
        $site_name = 'qqweibo';

        $_SESSION[$site_name]['last_key']['oauth_token'] = '75eb6362d88a4676913da7f8a83a27f4';
        $_SESSION[$site_name]['last_key']['oauth_token_secret'] = '89ef70c1905e92e03c3495e51c1957cc';
        $_SESSION['tencent_oauth_token_secret'] = '89ef70c1905e92e03c3495e51c1957cc';
        $_SESSION['tencent_access_token'] = '75eb6362d88a4676913da7f8a83a27f4';

        $list = AnOpenApi($site_name)->getEmotions();
        $site_id = get_site_id($site_name);
        foreach ($list as $v) {
            $info = array(
                'phrase' => $v['name'],
                'type' => 0,
                'url' => $v['url'],
                'icon' => $v['url'],
                'value'=> '/'.$v['name'],
                'site_id' => $site_id
            );
            if (!_uri('emotion', array('site_id'=>$site_id, 'phrase'=>$v['name']))) {
                _model('emotion')->create($info);
            }
        }
        mail('liw@alltosun.com', 'qqweibo_emotion', var_export($list, TRUE));
        echo "ok";
    }

    public function emotion_renren()
    {
        $site_name = 'renren';

        $access_token = _uri('connect', array('connect_user_id'=>'247397096', 'connect_site_id'=>2), 'access_token');
        $_SESSION[$site_name]['token']['access_token'] = $access_token;

        $list = AnOpenApi($site_name)->getEmotion();
        $site_id = get_site_id($site_name);
        foreach ($list as $v) {
            $info = array(
            	'phrase' => $v['desc'],
                'icon' => $v['icon'],
                'url' => $v['icon'],
                'value' => $v['emotion'],
                'site_id' => $site_id
            );
            if (!_uri('emotion', array('site_id'=>$site_id, 'phrase'=>$v['desc']))) {
                _model('emotion')->create($info);
            }
        }
        mail('liw@alltosun.com', 'renren_emotion', var_export($list, TRUE));
        echo "ok";
    }

    public function emotion_kaixin()
    {
        $site_name = 'kaixin';
        $access_token = _uri('connect', array('connect_user_id'=>'133186861', 'connect_site_id'=>3), 'access_token');
        $_SESSION[$site_name]['token']['access_token'] = $access_token;
        $list = AnOpenApi($site_name)->getEmotion();
        $site_id = get_site_id($site_name);
        foreach ($list['response'] as $v) {
            $info = array(
                'phrase' => $v['title'],
                'url' => $v['src'],
                'icon' => $v['src'],
                'value' => $v['emotion'],
                'site_id' => $site_id
            );
            if (!_uri('emotion', array('site_id'=>$site_id, 'phrase'=>$v['title']))) {
                _model('emotion')->create($info);
            }
        }
        mail('liw@alltosun.com', 'kaixin_emotion', var_export($list, TRUE));
        echo "ok";
    }
}
?>